<template>
  <div class="shop-list">
    <div class="shop-list-inner">
      <div class="shop-list-title">商品列表
        <div class="shop-list-close" @click="close"></div>
      </div>
      <div class="shop-list-content">
        <div class="w-goods-list">
          <div class="w-goods-item" v-for="(item,i) in shops" :key="i">
            <div class="w-goods-item-inner">
              <img :src="item.logo" alt>
              <div class="w-goods-item-name">{{item.title}}</div>
              <div class="w-goods-item-price">
                <span>¥{{item.price}}</span>
                <!-- <span>¥689</span> -->
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="shop-list-footer">
        <span class="count">共{{pieces}}件</span>
        <span class="sum">总价</span>
        <span class="price">￥{{total}}</span>
        <div class="shop-list-buttons">
          <div class="shop-list-button car" @click="addCar">加入购物车</div>
          <div class="shop-list-button buy" @click="toBuyPage">立即购买</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    shops: {
      type: Array,
      default: function() {
        return [];
      }
    }
  },
  data() {
    return {
      shopList: [],
      pieces: 0
    };
  },
  watch: {
    shops(value) {
      this.pieces = value.length;
      this.shopList = value;
    }
  },
  methods: {
    close() {
      this.$emit("close", false);
    },
    addCar() {
      this.$emit("addCar");
    },
    toBuyPage() {
      this.$emit("BuyNow");
    }
  },
  computed: {
    total() {
      let sum = 0;
      this.shops.forEach(item => {
        sum += item.price;
      });
      return sum;
    }
  },
  mounted() {
    this.pieces = this.shops.length;
  }
};
</script>


<style lang="scss">
.shop-list {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 100%;
  background: #fff;
  .shop-list-inner {
    padding: 0 24px;
  }
  .shop-list-title {
    position: relative;
    height: 96px;
    line-height: 96px;
    font-size: 36px;
    border-bottom: 2px solid #e5e2e2;
  }
  .shop-list-close {
    position: absolute;
    top: 24px;
    right: 0;
    height: 44px;
    width: 44px;
    background: url("/images/close.png") 0 0 no-repeat / cover;
    cursor: pointer;
  }

  .shop-list-content {
    height: 700px;
    overflow: auto;
    .w-goods-item {
      display: inline-block;
      vertical-align: top;
      width: 50%;
      height: 374px;
      border-bottom: 2px solid #e5e2e2;
      .w-goods-item-inner {
        width: 238px;
        height: 238px;
        margin: 0 auto;
      }
      img {
        margin: 10px 0 6px 0;
        width: 100%;
        height: 238px;
      }
      .w-goods-item-name {
        font-size: 28px;
        margin-bottom: 10px;
        font-weight: 500;
      }
      .w-goods-item-name,
      .w-goods-item-price {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        text-align: center;
      }
      .w-goods-item-price {
        font-size: 28px;
        color: #d0021b;
      }
    }
    .w-goods-item:nth-child(odd) {
      border-right: 2px solid #e5e2e2;
    }
    .w-goods-item:nth-child(even) {
      margin-left: -2px;
    }
  }
  .shop-list-footer {
    display: flex;
    position: relative;
    height: 98px;
    line-height: 98px;
    border-top: 2px solid #e6e6e6;
    font-size: 28px;
    .sum {
      margin: 0 16px 0 24px;
    }
    .price {
      font-size: 32px;
      color: #d0021b;

      overflow: hidden;
      text-overflow: ellipsis;
      text-align: center;
    }
    .shop-list-buttons {
      text-align: right;
      flex: 1;
      .shop-list-button {
        display: inline-block;
        vertical-align: middle;
        width: 210px;
        height: 66px;
        line-height: 66px;
        color: #fff;
        font-size: 28px;
        text-align: center;
      }

      .car {
        background: #f1ad3d;
        border-radius: 30px 0 0 30px;
      }
      .buy {
        background: #5252a1;
        border-radius: 0 30px 30px 0;
        width: 180px;
      }
    }
  }
}
</style>
